package com.example.shop_2208.detail

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.shop_2208.entity.AddCarEntityResult
import com.example.shop_2208.entity.DetailEntityResult
import com.example.shop_2208.entity.GoodsEntityResult
import com.example.shop_2208.entity.ParamAddcar
import com.example.shop_2208.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class DetailViewModel:BaseViewModel() {
    val detailSuccess = MutableLiveData<DetailEntityResult>()
    val detailFail = MutableLiveData<String>()

    fun detail(goods_id:Int){
        viewModelScope.launch {
            try {
                detailSuccess.value = apiServer.detail(goods_id)
            }catch (e:Exception){
                detailFail.value = e.message
            }
        }
    }
    val addSuccess = MutableLiveData<AddCarEntityResult>()
    val addFail = MutableLiveData<String>()

    fun addCar(goods_id: Int,count:Int){
        viewModelScope.launch {
            try {
                val param = ParamAddcar(count, goods_id)
                addSuccess.value = apiServer.addCar(param)
            }catch (e:Exception){
                addFail.value = e.message
            }
        }

    }
}